package com.dfbz.demo02_线程安全测试;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
public class Demo05_lock锁 {
    public static void main(String[] args) {
        ReentrantLock lock = new ReentrantLock();


        new Thread() {
            @Override
            public void run() {
                for (int i = 0; i < 10000; i++) {
                    lock.lock();
                    System.out.print("我");
                    System.out.print("是");
                    System.out.print("中");
                    System.out.print("国");
                    System.out.print("人");
                    System.out.println();
                    lock.unlock();
                }
            }
        }.start();

        new Thread() {
            @Override
            public void run() {
                for (int i = 0; i < 10000; i++) {
                    lock.lock();
                    System.out.print("犯");
                    System.out.print("我");
                    System.out.print("中");
                    System.out.print("华");
                    System.out.print("者");
                    System.out.println();
                    lock.unlock();
                }
            }
        }.start();


    }
}
